<!doctype html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<html>
<head>
<meta charset="utf-8">
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/easyui.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/zTreeStyle.css">
<script src="${basePath }commonJs/jquery.min.js"></script>
<script src="${basePath }commonJs/jquery.easyui.min.js"></script>
<script src="${basePath }commonJs/jt_normal.js"></script>
<script src="${basePath }commonJs/jt_select.js"></script>
<script src="${basePath }commonJs/jquery.ztree.all.js"></script>
<script src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>


<script src="${basePath }commonJs/promotion/wolf_common.js"></script>
<script src="${basePath }commonJs/promotion/wolf_validation.js"></script>
<title>嘉童游乐中心-新增商品出库</title>

<SCRIPT type="text/javascript">

	/**存放当前选中商品编号*/
	var arry = [];
	jQuery(document).ready(function () {  
		var db_arry="${prdIdAll}";
		if(db_arry == null || db_arry == undefined || db_arry.length == 0){
			arry = [];
		}else{
			if(db_arry.length > 2 && db_arry.indexOf("[")==0){
				db_arry=db_arry.substring(1, db_arry.length);
				db_arry=db_arry.substring(0, db_arry.length-1);
				
				var tmp = db_arry.split(",");
				for(var i = 0 ; i < tmp.length ; i ++){
					var vvv = tmp[i] ;
					var value = vvv.replace(/\s+/g,"");
					arry.push(value);
				}
			}
			
		}
		/* checkBox_enter(); */
		checkBox_call();
		
		
	});
	/**获取数据，并且显示内容*/
	function checkBox_enter(){
		if(!checkBox_true_val()){
			checkBox_call();
			$('#addSelectGoods').window('close');
		}else{
			alertInfo("未选中任何商品！");
		}
		
	}
	
	/**代码抽取*/
	function checkBox_call(){
		if(arry.length > 0 ){
			$.ajax({ 
				url: "${basePath }promotion/seacheGblPrd.shtml",
				data:"prdIdList="+arry.toString(),
				dataType: 'json',
				type:'POST',
				success: function(data){
					show_prd_call(data.results);
		      	}
			});
		}
	}
	function show_prd_call(data){
		$("#pro_show_prd_table tr:not(:first)").remove(); 
		var zl_v = $("#fkDisId").find("option:selected").attr("zl");
		if(data != undefined){
			$.each(data,function(i,obj){
				var tr = "<tr id=\"tr"+obj.pkPrdId+"\">"+
			            	"<td>"+(i+1)+"</td>"+
			                "<td>"+obj.pkPrdId+"</td>"+
			                "<td>"+obj.prdName+"</td>"+
			                "<td>"+obj.cateName+"</td>"+
			                "<td>"+(obj.prdSpec==null?"-":obj.prdSpec)+"</td>"+
			                "<td>"+(obj.unitName==null?"-":obj.unitName)+"</td>"+
			                /* "<td>"+(obj.branchPrice==null?"-":obj.branchPrice)+"</td>"+
			                "<td>"+zl(obj.branchPrice,zl_v)+"</td>"+ */
			                "<td>"+(obj.productPrice==null?"-":obj.productPrice)+"</td>"+
			                "<td>"+zl(obj.productPrice,zl_v)+"</td>"+
			                "<td><input type=\"button\" value=\"删除\" class=\"btn_l\"  onClick=\"table_update_td_text('"+obj.pkPrdId+"');\"></td>"+
			            "</tr>";
			    $("#pro_show_prd_table").append(tr);
			});
		}
		
		/**绑定商品编号*/
		$("#prdlist").val(arry.toString());
	}
	/**计算折后价*/
	function zl(price,hszl){
		if(price == null || price == undefined || price == ''){
			return "";
		}
		if(hszl == null || hszl == undefined || hszl == '' || hszl <0){
			return price;
		}
		return (price*hszl).toFixed(2);
	}

	/**删除选中的商品*/
	function table_update_td_text(trId){
		$("#tr"+trId).remove();
		
		arry.remove(trId);
		$("#pro_show_prd_table tr").each(function(i,obj){
			if(i != 0){
				$(obj).children("td:eq(0)").html(i);
			}
		});
		$("#prdlist").val(arry.toString());
		  
	}
	
	function table_delete_td_text(trId){
		$.ajax({ 
			url: "${basePath }promotion/seachePrdCateTree.shtml",
			dataType: 'json',
			type:'POST',
			success: function(data){
				$.fn.zTree.init($("#sptree"), setting, data);
	      	}
		});
	}
	
	/**提交数据*/
	function form_submit(t){
		var ms = (t == 1 ? '提交':'保存');
		var flag = false ; 
		$.messager.confirm('提示', '你确定要'+ms+'吗?', function(r) {
			if(r){
				if(t == '2'){
					
					$("#date1").attr("data_v","dateR");
					$("#date1").attr("data_v_info","起始日期");
					$("#date2").attr("data_v","dateR");
					$("#date2").attr("data_v_info","结束日期");
					
					$("#campName").attr("data_v","not_empty");
					$("#campName").attr("data_v_info","活动名称");
				}else{
					$("#date1").attr("data_v","");
					$("#date1").attr("data_v_info","");
					$("#date2").attr("data_v","");
					$("#date2").attr("data_v_info","");
					
					$("#campName").attr("data_v","");
					$("#campName").attr("data_v_info","");
				}
				$('#status').val(t);
				wolf_v.v_bean.formId="pro_add_form";
				wolf_v.v_bean.alertType="5";
				wolf_v.v_bean.alertTypeCall=v_msg;
				wolf_v.v_validation();
				if(wolf_v.v_check_result){
					 $('#pro_add_form').submit();
					 flag = true;
				}
				flag = false;
			}
		});
		return flag;
		
	}
	function v_msg(t,arry){
		if(t == -1){
			if(wolf.isNotNull( arry ) && arry.length > 0){
				var obj = arry[arry.length - 1];
				alertInfo(obj.t.replace("&p",obj.d));
			}
		}
	}
	function eache_tr_zk(){
		var zl_v = $("#fkDisId").find("option:selected").attr("zl");
		$("#pro_show_prd_table tr").each(function(i,obj){
		     if(i != 0){
		    	 var price = $(obj).children("td:eq(6)").html();
		    	 var n_price = zl(price, zl_v);
		        $(obj).children("td:eq(7)").html(n_price);
		     }
		 });
	}
</SCRIPT>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
	      <shiro:hasPermission name="promotion/home.shtml">
					<li class="content_hover"><a
						href="${basePath }promotion/home.shtml"><i class="nav_icon_b"></i><br>限时打折</a></li>
				</shiro:hasPermission>
        </ul>
    </div>
    <form action="${basePath }promotion/editPromotion.shtml" id="pro_add_form" method="post">
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
    		<h1 class=""><font size="+1">活动设置</font></h1>
            <hr>
        	<dl class="fixed" style="overflow:hidden">
            	<dd><label>活动名称：</label>
            		<input type="text" class="iput_t w200" name="campName" value="${entity.campName }" >
            		<span class="file_single_dl_span">*</span>
            	</dd>
                <dd><label>活动设置人：</label>${loginUser.name}</dd>
                <dd><label id="currentDate">活动设置时间：</label>${currentDate }</dd>
            </dl>
        	<dl class="fixed" style="overflow:hidden">
                <dd><label>限时折扣：</label>
                	<div class="uboxstyle">
                        <select name="fkDisId" id="fkDisId"  data_v="not_empty" data_v_info="限时折扣 " onchange="eache_tr_zk()">
                        	<c:forEach items="${discountAll }" var="v">
                            	<option value="${v.pkDisId }" zl="${v.disValue }" ${v.pkDisId==entity.fkDisId?'selected':'' }>${v.disDesc }</option>
                            </c:forEach>
                        </select>
                    </div>
                </dd>
                <dd><label>活动范围：</label>
                	<div class="uboxstyle">
                       <%--  <select name="prdScope" id="prdScope">
                            <option value="1" ${entity.prdScope==1?'selected':''  }>全部商品</option>
                            <option  value="0" ${entity.prdScope==0?'selected':''  }>库存商品</option>
                        </select> --%>
                        <select name="fkBranId" id="fkBranId">
                       		<c:forEach items="${branAll }" var="bran" varStatus="cc">
                            	<c:choose>
	                            		<c:when test="${branId == 'ZB' }">
	                            			<c:if test="${bran.pkBranId !='ZB'}">
	                            				<option value="${bran.pkBranId}">${bran.branName }</option>
	                            			</c:if>
		                            	</c:when>
		                            	<c:when test="${branId != 'ZB' && branId ==bran.pkBranId }">
		                            		
		                            		<option value="${bran.pkBranId}">${bran.branName }</option>
		                            	</c:when>
		                            	
                            		</c:choose>
                            </c:forEach>
                        </select>
                    </div>
                </dd>
            </dl>
        	<dl class="fixed" style="overflow:hidden">
            	
                <dd><label>备注：</label><textarea class="textare w200" name="comments" >${entity.comments }</textarea></dd>
            	<dd  style="width: 700px !important;"><label>活动有效期：</label>
                	<input title="" type="text" name="startDateStr" id="date1" value="${entity.startDateStr }"  
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'date2\')}'})"
					class="Wdate iput_t w150" readonly /><span>至</span>
					<input title="" type="text" name="endDateStr" id="date2" value="${entity.endDateStr }"  
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'date1\')}'})"
					class="Wdate iput_t w150" readonly /><span class="file_single_dl_span">*</span>
                </dd>
            </dl>
        </div>
        <input type="hidden"  name="pkCampId" id="pkCampId" value="${entity.pkCampId }">
        <input type="hidden"  name="prdlist" id="prdlist" value="">
        <input type="hidden"  name="status" id="status" value="">
       </form>
        <table class="table" id="pro_show_prd_table">
                    	<tr>
                        	<th>序号</th>
                            <th>商品编号</th>
                            <th>商品名称</th>
                            <th>商品分类</th>
                            <th>规格</th>
                            <th>单位</th>
                            <th>商品原价</th> 
                            <th>折扣后价格</th> 
                             <th>操作</th> 
                        </tr>
                        
                    </table>
                    <div class="btm_btn m10">
                        <dl>
                        	<dd><input class="btn" type="button" value="新增" onClick="seache_prd();"></dd>
                            <!-- <dd><input class="btn" type="button" value="提交" onclick="javascript:$('#status').val(2);$('#pro_add_form').submit();"></dd>
                            <dd><input class="btn" type="button" value="保存" onclick="javascript:$('#status').val(1);$('#pro_add_form').submit();"></dd>
                             -->
                             
                            <dd><input class="btn" type="submit" value="提交" onclick="return form_submit('2');"></dd>
                            <dd><input class="btn" type="submit" value="保存" onclick="return form_submit('1');"></dd>
                             <dd><input class="btn" type="button" value="返回" onclick="javascript:window.location.href='${basePath }promotion/home.shtml'"></dd>
                            
                        </dl>
                    </div>
        </div>
    </div>
</div>
<!---弹出层 成员信息编w辑--->

<div id="addSelectGoods" class="easyui-window" title="新增打折商品" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1200px; height:400px;position:relative;">
    	<form  id="prd_seache_form" action="${basePath }promotion/seacheGblPrd.shtml">
	    	<div class="file_single_dl mt10">
	        	<dl>
	            	<dd><label>商品编号：</label><input type="text" class="iput_t w200" name="pkPrdId"></dd>
	                <dd><label>商品名称：</label><input type="text" class="iput_t w200" name="prdName"></dd> 
	                <dd><input type="button" class="btn ml10" value="查询" onclick="seache_prd()"></dd> 
	            </dl>
	        </div>
	        <input type="hidden" name="pageNo" id="pageNo_" value="1">
	        <input type="hidden" name="pageSize" value="7">
        </form>
        <form  id="prd_seache_ztree_form" action="${basePath }promotion/seacheCateIdGblPrd.shtml">
	    	
	    	<input type="hidden" name="pid" id="pid" value="">
	        <input type="hidden" name="pageNo"  id="_pageNo" value="1">
	        <input type="hidden" name="pageSize" value="7">
        </form>
        <div class="tab_normal mt10">
            <div class="payment_l tc" style="height:300px; overflow:auto;width: 220px"><div class="ztree" id="sptree"></div></div>
            <div style="width:850px; float:left; margin-left:20px;">
          	<table class="table" id="prd_table">
                    	<tr> 
                       		<th><input type="checkbox" id="prd_check_all" name="prd_check_all" onclick="checkbox_evn()"/></th>
                        	<th>序号</th>
                            <th>商品编号</th>
                            <th>商品名称</th>
                            <th>商品分类</th>
                            <th>规格</th>
                            <th>计量单位</th> 
                            <th>商品价格</th>
                        </tr>
                        <!-- <tr> 
                        	<td><input type="checkbox"/></td>
                        	<td>1</td>
                            <td>KP0001</td>
                            <td>可口可乐</td>
                            <td>饮料</td>
                            <td>100ML</td>
                            <td>瓶</td>
                            <td>2.5</td>
                        </tr>
                        <tr> 
                         <td><input type="checkbox"/></td>
                         	<td>6</td>
                            <td>KP0006</td>
                            <td>王老吉</td>
                            <td>饮料</td>
                            <td>100ML</td>
                            <td>瓶</td>
                            <td>3.5</td> 
                        </tr> -->
                    </table>
                    <input class="btn mt10" type="button" value="确定" onclick="checkBox_enter();">
                    <input class="btn mt10" type="button" value="返回" onclick="javascript:$('#addSelectGoods').window('close');">
                    
                    <!---翻页-->
                    <div class="page fr m10" id="prd_page">
                        <span>第3/2000页</span>
                        <span>首页</span>
                        <span>上一页</span>
                        <span><a href="#">下一页</a></span>
                        <span><a href="#">末页</a></span>
                        <span>跳转到<input type="text" class="black_text mlr5">页</span>
                    </div>
                    <!----->
            </div>
		</div>
</div>

<SCRIPT type="text/javascript">
$(document).ready(function(){
	loadTree();
});
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			callback:{
				onClick:treeClick
			}
		};

		
		Array.prototype.contains = function(obj) { 
			  var i = this.length; 
			  while (i--) { 
			    if (this[i] === obj) { 
			      return true; 
			    } 
			  } 
			  return false; 
			};
		
		/**获取商品分类树结构*/
		function loadTree(){
			$.ajax({ 
				url: "${basePath }promotion/seachePrdCateTree.shtml",
				dataType: 'json',
				type:'POST',
				success: function(data){
					$.fn.zTree.init($("#sptree"), setting, data);
		      	}
			});
		}
		
		/**搜索促销商品*/
		function seache_prd(){
			$('#addSelectGoods').window('open');
			$("[name='prd_check_all']").removeAttr("checked");
			$("#pageNo_").val(1);
			var form = $("#prd_seache_form"); 
		     var pagebean = new PageBean(form);
		     pagebean.setTableId("prd_table");
		     pagebean.setCallback(seache_prd_call);
		     pagebean.setFootId("prd_page");
		     setPagebeanObj(pagebean); 
		     pagebean.doPage();
		}
		function seache_prd_call(data){
			if(data != undefined){
				$.each(data,function(i,obj){
					var tr = "<tr>"+
				            	"<td><input type=\"checkbox\" id=\"pkPrdId_check\" name=\"pkPrdId_check\" value='"+obj.pkPrdId+"'/></td>"+
				            	"<td>"+(i+1)+"</td>"+
				                "<td>"+obj.pkPrdId+"</td>"+
				                "<td>"+obj.prdName+"</td>"+
				                "<td>"+obj.cateName+"</td>"+
				                "<td>"+(obj.prdSpec==null?"-":obj.prdSpec)+"</td>"+
				                "<td>"+(obj.unitName==null?"-":obj.unitName)+"</td>"+
				                /* "<td>"+(obj.branchPrice==null?"-":obj.branchPrice)+"</td>"+ */
				                "<td>"+(obj.productPrice==null?"-":obj.productPrice)+"</td>"+
				            "</tr>";
				    $("#prd_table").append(tr);
				});
			}
		}
		/**单击类型查询数据*/
		function treeClick(event, treeId, treeNode){
			$("#pid").val(treeNode.id);
			$("#_pageNo").val(1);
			var form = $("#prd_seache_ztree_form"); 
		     var pagebean = new PageBean(form);
		     pagebean.setTableId("prd_table");
		     pagebean.setCallback(seache_prd_call);
		     pagebean.setFootId("prd_page");
		     setPagebeanObj(pagebean); 
		     pagebean.doPage();
		}
		/**全选 不选*/
		function checkbox_evn(){
		   if($("#prd_check_all").attr("checked"))     
		   {     
			 $("[name='pkPrdId_check']").attr("checked",'true');  
		   }     
		   else    
		   {     
			 $("[name='pkPrdId_check']").removeAttr("checked");
		   }     
		   
		}
		/**获取所有选中的值*/
		function checkBox_true_val(){
			var flag = true;
			$("input[name='pkPrdId_check']").each(function(){
				 if($(this).attr("checked")){
					 var v = $(this).val();
					 if(!arry.contains(v)){
						 arry.push($(this).val());
					 }
					 flag = false; 
				 } 
			});
			$("[name='prd_check_all']").removeAttr("checked");
			return flag;
		}
		
		
	</SCRIPT>
</body>
</html>














>